<? 
	if(isset($_POST['btngo']))
	{
		require("required/dbconnect.php");
		$pageno=$_POST['pageno'];
		header("Location:order_view.php?page=$pageno");
	}
	
			
	$title="View all products"; 
	$pageid="1";
	$accessid="a00";
	
	require("required/dbconnect.php"); 
	require("required/function.php");
	require("required/header.php");
	
	checkAccess("allow_online_sales_view",1);
	
?>
<script src="required/js/jquery-1.4.2.js"></script>
<script src="required/js/common_javascript.js"></script>
<?	
		
	if(!empty($_GET['action']))
	{
		switch($_GET['action'])
		{
			case 1:
				$msg="<div class='dw_success'>Data inserted</div>";
				break;
			case 2:
				$msg="<div class='dw_success'>Data Deleted</div>";
				break;
			case 3:
				$msg="<div class='dw_success'>Data Updated</div>";
				break;	
			default:
				$msg="";
				break;
		}
		echo "<script>displayMsg('divMsg')</script>";	
	}else{
		$msg="";
	}
	
	
	
	
	if(isset($_POST['btnsubmit']))
	{
		$status=$_POST['status'];
		
		if($status=="")
		{
			$option="<option value=''>All</option>";
			$status_q="";
		}
		else
		{
			$option="<option value='$status'>".redeemstatus_eng($status)."</option>";
			$status_q="and status=$status";
		}
	}
	elseif(!empty($_GET['status']))
	{
		$status=$_GET['status'];
		
		if($status==0)
		{
			$option="<option value=''>All</option>";
			$status_q="";
		}
		else
		{
			$option="<option value='$status'>".redeemstatus_eng($status)."</option>";
			$status_q="and status=$status";
		}
	}
	else
	{
		$option="<option value=''>All</option>";
		$status_q="";
	}
		
	
	if(empty($_GET['page']))
	{
		$page="1";
	}
	else
	{
		$page=$_GET['page'];
	}
	
	$totalperpage=30;

	$from=($page-1)*$totalperpage;	
	
	$get_bill=mysql_query("select * from os_bill_details where is_redeem=1 $status_q order by create_date desc limit $from,$totalperpage")or die(mysql_error());
	$get_total=mysql_query("select * from os_bill_details where is_redeem=1 $status_q")or die(mysql_error());
	
?>
<table width="100%">

<?
	$count=mysql_num_rows($get_total);

	$totalpage=$count/$totalperpage;
	
	if($count%$totalperpage>0)
	{
		if(round($totalpage)>$totalpage)
		{
			$totalpage=round($totalpage);
		}
		else
		{
			$totalpage=round($totalpage+1);
		}
	}
	else
	{
		$totalpage=round($totalpage);
	}
	
	
	$nextpage=$page+1;
	$prepage=$page-1;
	
	
?>
<td align="left" valign="top">
	<div class="title">View All Gift Redemption</div>
     <div id="divMsg"><?= $msg ?></div>
	<table width="100%" cellpadding="2" cellspacing="1" >
		<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm">
						<td width="49%" colspan="5">
							view status 
							<select name="status" class="text">
								<?= $option ?>
							    <option value="">All</option>
								<option value="0">Pending</option>
                                <option value="1">Confirmed</option>
                                <option value="2">Sent</option>
								<option value="3">Received</option>
							</select>
							<input type="submit" value="Go" class="button" name="btnsubmit">
						</td>	
						</form>	
		<? if(mysql_num_rows($get_bill)==0){ ?>
		<tr>
		 <td height="200" valign="middle" colspan="8" align="center">
			<font color="#FF0000">- No record found -</font><br>
		 </td>
		</tr>
		<? }else{ ?>
		<tr>
            <td width="100%" colspan="6" align="left"><br><br>
                <table width="100%" cellpadding="0" cellspacing="0" >
                    <td width="51%" height="45">
                    <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
                    <input type="button" class="button" value="<<" onClick="window.open('order_view.php?page=1','_self')">
                    <input type="button" class="button" value="<" onClick="window.open('order_view.php?page=<?= $prepage ?>','_self')">
                    
                    Page <input type="text" name="pageno" value="<?= $page ?>" size="2" maxlength="3" class="text"> of <?= $totalpage ?>
                    <input type="submit" value="Go" class="button" name="btngo">
                    <? if($page==$totalpage){ ?>	
                    <input type="button" class="button" value=">" >
                    <? }else{ ?>
                    <input type="button" class="button" value=">" onClick="window.open('order_view.php?page=<?= $nextpage ?>','_self')">
                    <? } ?>
                    <input type="button" class="button" value=">>" onClick="window.open('order_view.php?page=<?= $totalpage ?>','_self')">
                    
                    </form>
                    
                    </td>
                
              </table>
            </td>
        </tr>
		<tr>
        	<td width="100%" colspan="4">
            <table class="solidborder" width="100%" >
              <tr class="table_header">
                  <td width="15%">Order #</td>
                <td width="15%">Redeemed Date</td>
               	<td width="15%">Member</td>
                <td width="15%">Total Points</td> 
                <td width="15%">Status</td>
                </tr>
		<?
			$no=$from+1;
			while($c=mysql_fetch_array($get_bill))
			{
				if($no%2==0)
				{
					$class1="table_item_even";
					$class2="table_item_odd";
				}
				else
				{
					$class1="table_item_odd";
					$class2="table_item_even";
				}
				$get_member=mysql_query("select * from os_member where id=".$c['uid']);
												
				if(mysql_num_rows($get_member)==0)
				{
					$name="- user not found -";
				}
				else
				{
					$name="<a href='member_viewfull.php?id=".mysql_result($get_member,0,"id")."'>".mysql_result($get_member,0,"username")."</a>";
				}
				
				
				
		?>	
		 <tr height="30" valign="top" class="<?= $class1 ?>"  onmouseover="this.className='table_item_mouseover'" 
                            onmouseout="this.className='<?= $class1 ?>'">
			<td><a href="order_viewfull.php?id=<?= $c['id'] ?>"><?= $c['invoice_number'] ?></a></td>
            <td><?= $c['create_date'] ?></td>
            <td><?= $c['receiver_name'] ?></td> 
            <td align="right"><?= $c['total_amount'] ?></td>
            <td>
			<?= redeemstatus_eng($c['status']) ?>
            
            </td>
			
           
			
		</tr>
		<? $no++;}
		?>
		</table>
		</td>
		<?
		
		} ?>
		
	</table>
	</td>
</table>

<? require("required/footer.php"); ?>

